package com.haoan.index.service.impl;


import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.LcNewsMapper;
import com.haoan.index.domain.LcNews;
import com.haoan.index.service.LcNewsService;

/**
 * 新闻中心Service业务层处理
 * 
 * @author autoGen
 * @date 2025-03-19
 */
@Service
public class LcNewsServiceImpl extends ServiceImpl<LcNewsMapper,LcNews> implements LcNewsService
{
    /**
     * 查询新闻中心
     * 
     * @param id 新闻中心主键
     * @return 新闻中心
     */
    @Override
    public LcNews selectLcNewsById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询新闻中心列表
     * 
     * @param lcNews 新闻中心
     * @return 新闻中心
     */
    @Override
    public List<LcNews> selectLcNewsList(LcNews lcNews)
    {
        LambdaQueryWrapper<LcNews> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(lcNews.getId() != null, LcNews::getId, lcNews.getId());
        queryWrapper.like(lcNews.getTitle() != null, LcNews::getTitle, lcNews.getTitle());
        queryWrapper.eq(lcNews.getImage() != null, LcNews::getImage, lcNews.getImage());
        queryWrapper.eq(lcNews.getContent() != null, LcNews::getContent, lcNews.getContent());
        queryWrapper.eq(lcNews.getType() != null, LcNews::getType, lcNews.getType());
        queryWrapper.like(lcNews.getPublishedAt() != null, LcNews::getPublishedAt, lcNews.getPublishedAt());
        queryWrapper.like(lcNews.getCreatedAt() != null, LcNews::getCreatedAt, lcNews.getCreatedAt());
        queryWrapper.like(lcNews.getUpdatedAt() != null, LcNews::getUpdatedAt, lcNews.getUpdatedAt());
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增新闻中心
     * 
     * @param lcNews 新闻中心
     * @return 结果
     */
    @Transactional
    @Override
    public int insertLcNews(LcNews lcNews)
    {
        return baseMapper.insert(lcNews);
    }

    /**
     * 修改新闻中心
     * 
     * @param lcNews 新闻中心
     * @return 结果
     */
    @Transactional
    @Override
    public int updateLcNews(LcNews lcNews)
    {
        return baseMapper.updateById(lcNews);
    }

    /**
     * 批量删除新闻中心
     * 
     * @param ids 需要删除的新闻中心主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteLcNewsByIds(Long [] ids)
    {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除新闻中心信息
     * 
     * @param id 新闻中心主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        return baseMapper.deleteById(id);
    }
}
